package com.lisx.module_note.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class TimeUtils {

    public static final SimpleDateFormat DEFAULT_SDF2 = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
    public static final SimpleDateFormat DEFAULT_SDF3 = new SimpleDateFormat("HH:mm", Locale.getDefault());

    public static String parseDefaultTimeLong(long utcTime) {
        return parseTimeLong(utcTime, DEFAULT_SDF2);
    }

    public static String parseHMTimeLong(long utcTime) {
        return parseTimeLong(utcTime, DEFAULT_SDF3);
    }

    public static String parseTimeLong(long milliseconds, SimpleDateFormat format) {
        try {
            return format.format(new Date(milliseconds * 1000));

        } catch (Exception e) {
            return "";
        }
    }

    public static String parseYear(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        int year = calendar.get(Calendar.YEAR);
        return year + "";
    }

    public static String parseMonth(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        int month = calendar.get(Calendar.MONTH);
        return (month + 1) + "";
    }

    public static String parseDay(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        return day + "";
    }

    public static boolean isSameYear(long time1, long time2) {
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(new Date(time1));

        Calendar calendar2 = Calendar.getInstance();
        calendar2.setTime(new Date(time2));
        if (calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)) {
            return true;
        }
        return false;
    }

    public static String getWeek(long time) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(time));
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        String week = "";
        if (dayOfWeek == 1) {
            week = "周日";
        } else if (dayOfWeek == 2) {
            week = "周一";
        } else if (dayOfWeek == 3) {
            week = "周二";
        } else if (dayOfWeek == 4) {
            week = "周三";
        } else if (dayOfWeek == 5) {
            week = "周四";
        } else if (dayOfWeek == 6) {
            week = "周五";
        } else if (dayOfWeek == 7) {
            week = "周六";
        }
        return week;
    }
}
